//设置cookie
function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

//获取cookie
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
    }
    return "";
}

//清除cookie
function clearCookie(name) {
    setCookie(name, "", -1);
}

//判断是否需要重新登录
function isRelogin(error_code){
    if (error_code == "40001")
    {
        goToLoginPage();
        return true;
    }
    return false;
}

//返回登录页面
function goToLoginPage(){
    localStorage["data"] = "";
    localStorage["status"] = "";
    window.location.href = "Login.html";
}

//打电话
function toCall(phoneNumber) {
    alert("toCall: phone_number = " + phoneNumber);
    Ponto.invoke(
                 "Messaging",
                 "toCall",
                 {phone_number: phoneNumber},
                 null,
                 null);
}

//设状态
function setStatus(deliveryId, statusA){
    alert("setStatus: delivery_id = " + deliveryId + ", status = " + statusA);
    Ponto.invoke(
                 "Messaging",
                 "setStatus",
                 {delivery_id: deliveryId,
                 status: statusA},
                 null,
                 null);
}



function login(phone_number, access_code){
    alert("setStatus: phone_number = " + phone_number + ", access_code = " + access_code);
    Ponto.invoke(
                 "Messaging",
                 "login",
                 {phone_number: phone_number,
                 access_code: access_code},
                 null,
                 null);
}
